package code._10string._04sort.demo3;

import java.util.Arrays;
import java.util.Comparator;

public class Main {
    public static void main(String[] args) {
        Student2 s1 = new Student2("zs", 22, 88);
        Student2 s2 = new Student2("ls", 21, 59);
        Student2 s3 = new Student2("ww", 20, 77);
        Student2 s4 = new Student2("zl", 25, 66);
        Student2 s5 = new Student2("sq", 21, 99);
        // 放入数组中
        Student2[] students = {s1, s2, s3, s4, s5};

        System.out.println("排序前:");
        System.out.println(Arrays.toString(students));

        //使用匿名内部类
        /*Arrays.sort(students, new Comparator<Student2>() {
            @Override
            public int compare(Student2 o1, Student2 o2) {
                return o1.score-o2.score;
            }
        });*/

        //使用Lambda表达式
        Arrays.sort(students,(o1,o2)-> o1.score-o2.score);

        System.out.println("排序后:");
        System.out.println(Arrays.toString(students));
    }
}
